﻿using System;
using System.Data;
using Model.Data;
using Model;
using DataAccess;
using BusinessLogic.BusinessRules;


namespace BusinessLogic.ClassFactory
{
    /// <summary>
    /// SyntheticTableFactory 的摘要说明。
    /// </summary>
    public class SyntheticTableFactory : BaseFactory
    {
        public SyntheticTableFactory()
            : base()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        public SyntheticTableFactory(DBManager l_DBManager)
            : base(l_DBManager)
        {
        }
        public SyntheticTable NewInstance()
        {
            SyntheticTableAccess l_Access = new SyntheticTableAccess(m_Manager);
            SyntheticTable objSyntheticTable = new SyntheticTable(this.m_Manager, l_Access);
            objSyntheticTable.NewDataSet();
            objSyntheticTable.SelectRow(0);
            return objSyntheticTable;
        }

        public SyntheticTable CreatorBySql(string Sql)
        {
            SyntheticTableAccess l_Access = new SyntheticTableAccess(m_Manager);
            SyntheticTable objSyntheticTable = new SyntheticTable(this.m_Manager, l_Access);
            DataSet l_ds = new SyntheticTableData();
            if (l_Access.QueryBySql(ref l_ds, Sql) < 1)
            {
                return null;
            }
            objSyntheticTable.SetDataSet(l_ds);
            objSyntheticTable.SelectRow(0);
            return objSyntheticTable;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="intSTableID"></param>
        /// <returns></returns>
        public SyntheticTable Creator(int intSTableID)
        {
            SyntheticTableAccess l_Access = new SyntheticTableAccess(m_Manager);
            SyntheticTable objSyntheticTable = new SyntheticTable(this.m_Manager, l_Access);
            DataSet l_ds = new SyntheticTableData();
            if (l_Access.QueryByID(ref l_ds, intSTableID) < 1)
            {
                return null;
            }
            objSyntheticTable.SetDataSet(l_ds);
            objSyntheticTable.SelectRow(0);
            return objSyntheticTable;
        }

        public SyntheticTable Creator()
        {
            SyntheticTableAccess l_Access = new SyntheticTableAccess(m_Manager);
            SyntheticTable objSyntheticTable = new SyntheticTable(this.m_Manager, l_Access);
            DataSet l_ds = new SyntheticTableData();
            if (l_Access.QueryAll(ref l_ds) < 1)
            {
                return null;

            }
            objSyntheticTable.SetDataSet(l_ds);
            objSyntheticTable.SelectRow(0);
            return objSyntheticTable;
        }

    }
}
